<?php

function fetchUrl($url,$options=array()) {
	$ch = curl_init($url);
	$defaultOption = array(
			CURLOPT_HEADER => 0,
			CURLOPT_TIMEOUT => 10,
			CURLOPT_RETURNTRANSFER=>1,
	);
	$options = $defaultOption+$options;
	foreach ($options as $k=>$v){
		curl_setopt($ch,$k,$v);
	}
	$res = curl_exec($ch); // Run it!
	if (curl_errno($ch)) {
		echo curl_error($ch),"\n";
		curl_close($ch);
		return false;
	}else {
		curl_close($ch);
		return $res;
	}
}

		$json = array(
			'agt_ip'=>	'221.203.48.7',
			'agt_port'=>9999,
			'agt_type' => 'HTTP',
		);
		$json = (object)$json;
		if ($json) {
			$agentType	=	array(
					'HTTP'	=>	CURLPROXY_HTTP,
					'SOCKS4'=>	CURLPROXY_SOCKS4,
					'SOCKS5'=>	CURLPROXY_SOCKS5,
			);
			$options = array(
				CURLOPT_HTTPPROXYTUNNEL	=>	true,
				CURLOPT_PROXYAUTH=>CURLAUTH_BASIC,
				CURLOPT_PROXY=>	$json->agt_ip,
				CURLOPT_PROXYPORT=>intval($json->agt_port),
					//代理模式
				CURLOPT_PROXYTYPE=>$agentType[$json->agt_type],
				CURLOPT_HTTPHEADER=>	array(
						'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
						'Connection: keep-alive',
// 						"Cache-Control: max-age=0",
						'Accept-Language: zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3',
                        //"X_FORWARDED_FOR: {$json->agt_ip}"
				),
				CURLOPT_ENCODING=> 'gzip,deflate',
				CURLOPT_USERAGENT=>'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.49 Safari/537.36',
                CURLOPT_CUSTOMREQUEST=>'GET'
			);
			$html = fetchUrl('http://kojiki.server.ne.jp/etc/pj235.cgi?wx',$options);
			echo $html;
			//echo fetchUrl('http://iframe.ip138.com/ic.asp',$options);
		}
